package junior.util.exception.validate;

import org.apache.commons.lang3.StringUtils;

import java.util.function.Predicate;

public class Validators {
 
	public static void notNull(Object value, String name) {
		if (value == null) throw new DataValidateException("notNull", name);
	}
	
	public static void notBlank(String value, String name) {
	    if (StringUtils.isEmpty(name)) throw new DataValidateException("notBlank", name);
	}
	
	public static void maxLength(String name, long maxLength, long actualLength) {
		if (actualLength > maxLength) throw new DataValidateException("maxLength", name, maxLength, actualLength);
	}
    
    public static void minLength(String name, long minLength, long actualLength) {
        if (actualLength < minLength) throw new DataValidateException("minLength", name, minLength, actualLength);
    }
    
    /*------------------------------------------------*/
    
    public static RuleBuilder ruleBuilder() {
        return new RuleBuilder();
    }
    
    static class RuleBuilder {
    
        public RuleBuilder and() {
        
            return this;
        }
    
        public RuleBuilder or() {
        
            return this;
        }
    
        public RuleBuilder range(String field, int min, int max) {
        
            return this;
        }
        public RuleBuilder min(String field, int min) {
        
            return this;
        }
        public RuleBuilder max(String field, int max) {
        
            return this;
        }
    
        public RuleBuilder notNull(String field, int min, int max) {
        
            return this;
        }
        public RuleBuilder isNull(String field, int min) {
        
            return this;
        }
        public RuleBuilder url(String field) {
        
            return this;
        }
        public RuleBuilder email(String field) {
        
            return this;
        }
        public RuleBuilder mobile(String field) {
        
            return this;
        }
        public RuleBuilder regex(String field, String pattern) {
        
            return this;
        }
    
        public void doValidate() throws DataValidateException {
        
        }
    
        public Predicate<Object> toPredicate() {
        
            return null;
        }
    }
    
    interface Rule {
        
        boolean validate(String property, Object value);
        
        String getErrorMessage(String property, Object value);
    }
    
    
}
